package com.example.codegen;

import com.example.utils.CJUtils;
import com.example.utils.classNode;

public class Field implements AstNode {
    public boolean isStatic;
    public Type fieldType;
    public Variable fieldName;
    public String className;

    public Field(boolean isStatic, Type type, Variable s, String className) {
        this.isStatic = isStatic;
        this.fieldType = type;
        this.fieldName = s;
        this.className = className;
    }

    public String toJava() {
        return "public " + (isStatic ? "static " : "") + fieldType.toJava() + " " + fieldName.toJava() + ";";
    }

    public String toGo() {
        // golang use upper case (leading character) for public field
        return fieldName.toGo().toUpperCase() + " " + fieldType.toGo();
    }

    @Override
    public String toJs() {
        if (isStatic)
            return "static " + fieldName.toJs() + " = \" \";";
        else
            return "this." + fieldName.toJs() + " = \" \";";
    }

    @Override
    public String toCSharp() {
        return "public " + (isStatic ? "static " : "") + fieldType.toCSharp() + " " + fieldName.toCSharp() + ";";
    }

    public String toCJ() {
        return "public " + (isStatic ? "static " : "") + "var "+(CJUtils.isVariableNameNormalized ? className+ "_" + fieldName.toCJ() : fieldName.toCJ())+ " : " + fieldType.toCJ() + " = " + CJUtils.getDefaultValue(fieldType.toCJ());
    }
}
